package com.platform.usercenter.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.platform.common.core.domain.entity.SysDept;
import com.platform.usercenter.domain.SysMenuTreeDTO;
import com.platform.usercenter.domain.SysOrganizationDept;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 树结构实体类
 * @Author: wcs
 * @Date: 2024-11-15 14:25:48
 **/
@Data
public class TreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 菜单类型
     */
    private String menuType;


    /**
     * 应用ID
     */
    private Long appSceneId;

    /**
     * 应用场景名称
     */
    private String sceneName;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect(SysDept dept) {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysOrganizationDept dept) {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenuTreeDTO menu) {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.menuType = menu.getMenuType();
        this.appSceneId = menu.getAppSceneId();
        this.sceneName = menu.getSceneName();
        if (!CollectionUtils.isEmpty(menu.getChildren())) {
            this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }
    }
}
